package edu.cmu.fithub.formbeans;

import java.util.ArrayList;
import java.util.List;

import org.mybeans.form.FormBean;

public class GroupForm extends FormBean {

	private String groupName;
	private String groupDesc;
	private String groupType;

	public String getGroupName() {
		return groupName;
	}

	public void setGroupName(String groupName) {
		this.groupName = groupName;
	}

	public String getGroupDesc() {
		return groupDesc;
	}

	public void setGroupDesc(String groupDesc) {
		this.groupDesc = groupDesc;
	}

	public String getGroupType() {
		return groupType;
	}

	public void setGroupType(String groupType) {
		this.groupType = groupType;
	}

	public List<String> getValidationErrors() {
		List<String> errors = new ArrayList<String>();

		if (groupName == null || groupName.length() == 0) {
			errors.add("Group Name is required");
		} else if (groupName.matches(".*[<>].*")) {
			errors.add("Group Name may not contain angle brackets");
			groupName = groupName.replaceAll(">", "&gt;");
			groupName = groupName.replaceAll("<", "&lt;");
			groupName = groupName.replaceAll(" ", "&nbsp;");
		}

		if (groupDesc == null || groupDesc.length() == 0) {
			errors.add("Group Description is required");
		} else if (groupDesc.matches(".*[<>].*")) {
			errors.add("Group Description may not contain angle brackets");
			groupDesc = groupDesc.replaceAll(">", "&gt;");
			groupDesc = groupDesc.replaceAll("<", "&lt;");
			groupDesc = groupDesc.replaceAll(" ", "&nbsp;");
		}
		
		if (groupType == null || groupDesc.length() == 0) {
			errors.add("Group Type is required");
		} else if (groupType.matches(".*[<>].*")) {
			errors.add("Group Type may not contain angle brackets");
			groupType = groupType.replaceAll(">", "&gt;");
			groupType = groupType.replaceAll("<", "&lt;");
			groupType = groupType.replaceAll(" ", "&nbsp;");
		}

		return errors;
	}
}
